package com.example.wechatbot.service;


import com.github.jaemon.dinger.DingerSender;
import com.github.jaemon.dinger.core.entity.DingerRequest;
import com.github.jaemon.dinger.core.entity.DingerResponse;
import com.github.jaemon.dinger.core.entity.enums.DingerType;
import com.github.jaemon.dinger.core.entity.enums.MessageSubType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageService {

    @Autowired
    private DingerSender dingerSender;

    /**
     * 发送文本消息
     * @param content 消息内容
     * @return 响应结果
     */
    public DingerResponse sendTextMessage(String content) {
        return dingerSender.send(
                DingerType.WETALK,
                MessageSubType.TEXT,
                DingerRequest.request(content)
        );
    }

    /**
     * 发送文本消息并@指定人员
     * @param content 消息内容
     * @param phones 需要@的手机号列表
     * @return 响应结果
     */
    public DingerResponse sendTextMessageWithAt(String content, List<String> phones) {
        return dingerSender.send(
                DingerType.WETALK,
                MessageSubType.TEXT,
                DingerRequest.request(content, phones)
        );
    }

    /**
     * 发送文本消息并@所有人
     * @param content 消息内容
     * @return 响应结果
     */
    public DingerResponse sendTextMessageAtAll(String content) {
        return dingerSender.send(
                DingerType.WETALK,
                MessageSubType.TEXT,
                DingerRequest.request(content, true)
        );
    }

    /**
     * 发送Markdown消息
     * @param content Markdown内容
     * @param title 标题
     * @return 响应结果
     */
    public DingerResponse sendMarkdownMessage(String content, String title) {
        return dingerSender.send(
                DingerType.WETALK,
                MessageSubType.MARKDOWN,
                DingerRequest.request(content, title)
        );
    }
}
